Skip to content

fix: preserve original key in _stat_for() option lookup#2

Closed
Koan-Bot wants to merge 12 commits intomasterfrom
koan.atoomic/fix-stat-for-key-lookup
Closed

fix: preserve original key in _stat_for() option lookup#2
Koan-Bot wants to merge 12 commits intomasterfrom
koan.atoomic/fix-stat-for-key-lookup

Conversation

@Koan-Bot
Copy link
Copy Markdown
Collaborator

@Koan-Bot Koan-Bot commented Mar 7, 2026

What

Fix _stat_for() so options with st_ prefix or mixed case are correctly applied.

Why

The loop variable $k was modified in-place (lowercased + prefix stripped), then used to index back into the original %$opts hash. Options like st_size => 42 or SIZE => 42 were silently dropped because the modified key didn't match the original hash entry.

How

Introduced a separate $name variable for normalization, preserving the original $k for the hash lookup.

Testing

Added 4 tests to t/stat-helpers.t covering st_ prefix, uppercase, and mixed-case keys. Full suite passes (1076 tests).

Koan-Bot and others added 12 commits February 22, 2026 00:53
_check() stored the file argument in $_last_call_for for -X _ caching.
When the argument was a filehandle reference (not a string path), this
prevented the filehandle from being garbage collected, keeping the
underlying file descriptor open.

This caused "spooky action-at-a-distance" bugs: e.g. a socketpair read
hanging because a dup'd write-end filehandle was kept alive by the
leaked reference, even after leaving scope.

Fix: only cache string filenames in $_last_call_for, not references.

Ref: cpan-authors/Test-MockFile#179

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ef-leak

fix: prevent filehandle reference leak in stat override
Add CLAUDE.md with project guidance for Claude Code sessions.
Exclude CLAUDE.md and local/ directory from Dist::Zilla GatherDir
so they don't end up in the CPAN tarball.
_stat_for() lowercased $k and stripped the st_ prefix in-place, then
used the modified $k to index into the original %$opts hash. This
silently dropped any option passed with an st_ prefix (e.g. st_size)
or mixed case (e.g. SIZE), because the modified key no longer matched
the original hash entry.

Use a separate $name variable for normalization so the original $k is
preserved for the hash lookup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@atoomic
Copy link
Copy Markdown
Owner

atoomic commented Mar 7, 2026

need to resubmit to the parent repo

@atoomic
Copy link
Copy Markdown
Owner

atoomic commented Apr 23, 2026

@Koan-Bot squash

@Koan-Bot
Copy link
Copy Markdown
Collaborator Author

Superseded by a more comprehensive fix in upstream/main that includes both key preservation AND unknown key validation with helpful error messages. Closing.

@Koan-Bot Koan-Bot closed this Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants